using TMPro;
using UnityEngine;
using UnityEngine.UI;


namespace BackpackSystem
{
    /// <summary>
    /// 
    /// </summary>
    public class Example : MonoBehaviour
    {
        [Tooltip("组件项|引用"), SerializeField] InventoryUI m_InventoryUI;


        [Header("库存详细")]
        [Tooltip("描述项|文本"), SerializeField] public TextMeshProUGUI TMP_Description;
        [Tooltip("图文项|物品"), SerializeField] public Image IMG_Icon;


        private void Start()
        {
            InventoryAsset.Load();

            // 订阅信息
            this.m_InventoryUI.ItemSelectEvent += OnDetailUpdated;

            this.m_InventoryUI = FindFirstObjectByType<InventoryUI>();
            this.m_InventoryUI.InitEnvironment();
            this.m_InventoryUI.InitInventory(4, 6);

            //Canvas.ForceUpdateCanvases();


            this.m_InventoryUI.Add(ItemType.Capsule);
            this.m_InventoryUI.Add(ItemType.Capsule);
            this.m_InventoryUI.Add(ItemType.Cube);
            this.m_InventoryUI.Add(ItemType.Cube);
            this.m_InventoryUI.Add(ItemType.Cube);
            this.m_InventoryUI.Add(ItemType.Cube);
            this.m_InventoryUI.Add(ItemType.Sphere);
            this.m_InventoryUI.Add(ItemType.Cylinder);
            this.m_InventoryUI.Add(ItemType.Cylinder);
            this.m_InventoryUI.Add(ItemType.Cylinder);
            this.m_InventoryUI.Add(ItemType.Cylinder);
            this.m_InventoryUI.Add(ItemType.Cylinder);
        }





        private void Update()
        {


            if (Input.GetKeyDown(KeyCode.Space))
            {
                this.m_InventoryUI.Add(ItemType.Capsule);
                this.m_InventoryUI.Add(ItemType.Capsule);
                this.m_InventoryUI.Add(ItemType.Cube);
                this.m_InventoryUI.Add(ItemType.Cube);
                this.m_InventoryUI.Add(ItemType.Sphere);
                this.m_InventoryUI.Add(ItemType.Cylinder);
            }
        }







        private void OnDetailUpdated(object sender, ItemSelectEvent ev)
        {
            this.TMP_Description.text = ev.ItemBase.Description;
            this.IMG_Icon.sprite = ev.ItemBase.Icon;
        }
    }
}